package com.example.springbootamqpconsumer1.lister;


import com.example.springbootamqpconsumer1.utils.AliCodeUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ConsumerLister {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @RabbitListener(queues = "java-queue")
    public void getMsg(Message message,String phone)throws Exception{
        System.out.println("我接受到了需要发送验证码的手机号："+phone);
        AliCodeUtils aliCodeUtils=new AliCodeUtils();
        aliCodeUtils.sendLoginCode(phone, "123455");
        redisTemplate.opsForValue().set(phone, "123455");
        redisTemplate.expire(phone, 1, TimeUnit.MINUTES);
    }

}
